<?php
class Boss extends CI_Controller{
    
    function __construct() {
        parent::__construct();
        $this->load->model('model_user');
        if($this->model_user->auth() == 0 || $this->model_user->auth() !== 1){
            redirect('login/index');
        }else{
            if ($this->session->userdata['type'] == 'pegawai1') {
                redirect('pegawai1');
            } else if($this->session->userdata['type'] == 'pegawai2'){
                redirect('pegawai2');
            }
        }
        $this->load->model('model_barang');
        $this->load->library('pagination');
    }
    
    function index(){
        $data['nama'] = $this->session->userdata['nama'];
        $data['main_content'] = 'welcome';
        $this->load->view('includes/template',$data);
    }
    
     function agree(){
       $perpage = 10; //tentukan jumlah data per halaman
            //untuk konfigurasi pagination
            $segment = $this->uri->segment(3);
        //untuk konfigurasi pagination
        $config = array(
            'base_url' => base_url() . 'boss/agree/',
            'total_rows' => $this->db->get('order')->num_rows(),
            'per_page' => $perpage,
            'num_links' => 10,
            'uri_segment' => 3,
            'full_tag_open' => '<div class="pagination pagination-centered paging"><ul>',
                'full_tag_close' => '</ul></div>',
                'num_tag_open' => '<li class="jawab">',
                'num_tag_close' => '</li>',
                'prev_tag_open' => '<li class="jawab">',
                'prev_tag_close' => '</li>',
                'next_tag_open' => '<li class="jawab">',
                'next_tag_close' => '</li>',
                'last_tag_open' => '<li>',
                'last_tag_close' => '</li>',
                'first_tag_open' => '<li>',
                'first_tag_close' => '</li>',
                'cur_tag_open' => '<li class="active"><span>',
                'cur_tag_close' => '</span></li>',
                'first_link' => false,
                'last_link' => false
        );    //inisialisasi pagination dn config di atas
        $this->pagination->initialize($config);
        $data['orders'] = $this->model_barang->getAlls($perpage, $segment);
        $data['main_content'] = 'agree/list';
        //$data['query'] = $this->model_barang->getAll();
        $this->load->view('includes/template', $data);
    }
    
    function showagree(){
       $perpage = 10; //tentukan jumlah data per halaman
            //untuk konfigurasi pagination
            $segment = $this->uri->segment(3);
        //untuk konfigurasi pagination
        $config = array(
            'base_url' => base_url() . 'boss/agree/',
            'total_rows' => $this->db->get('order')->num_rows(),
            'per_page' => $perpage,
            'num_links' => 10,
            'uri_segment' => 3,
            'full_tag_open' => '<div class="pagination pagination-centered paging"><ul>',
                'full_tag_close' => '</ul></div>',
                'num_tag_open' => '<li class="jawab">',
                'num_tag_close' => '</li>',
                'prev_tag_open' => '<li class="jawab">',
                'prev_tag_close' => '</li>',
                'next_tag_open' => '<li class="jawab">',
                'next_tag_close' => '</li>',
                'last_tag_open' => '<li>',
                'last_tag_close' => '</li>',
                'first_tag_open' => '<li>',
                'first_tag_close' => '</li>',
                'cur_tag_open' => '<li class="active"><span>',
                'cur_tag_close' => '</span></li>',
                'first_link' => false,
                'last_link' => false
        );    //inisialisasi pagination dn config di atas
        $this->pagination->initialize($config);
        $data['orders'] = $this->model_barang->getAlls($perpage, $segment);
        $this->load->view('agree/showagree', $data);
    }
    
    function order_detail($id){
        $result = $this->model_barang->getBarang($id);
        $data['id_order'] = $result['id_order'];
        $data['job_order'] = $result['job_order'];
        $data['no_sj'] = $result['no_sj'];
        $data['consgnee'] = $result['consgnee'];
        $data['origin'] = $result['origin'];
        $data['shipper'] = $result['shipper'];
        $data['via'] = $result['via'];
        $data['agent'] = $result['agent'];
        $data['ctn'] = $result['ctn'];
        $data['kg'] = $result['kg'];
        $data['m3'] = $result['m3'];
        $data['invoice'] = $result['invoice'];
        $data['description'] = $result['description'];
        $data['delivery'] = $result['delivery'];
        $data['penerimaan'] = $result['penerimaan'];
        $data['cost'] = $result['cost'];
        $data['profit'] = $result['profit'];
        $data['remarks'] = $result['remarks'];
        $data['etd_sin'] = $result['etd_sin'];
        $data['eta_jkt'] = $result['eta_jkt'];
        $data['agree'] = $result['agree'];
        $this->load->view('agree/details', $data);
    }
    
    function confirm(){
        if($this->model_barang->agree()){
            echo "<script type='text/javascript'>window.top.window.alertz('alert-success','Sukses !', 'Data berhasil diupdate');</script>";
        }else{
            echo "<script type='text/javascript'>window.top.window.alertz('alert-error','Gagal !', 'Data gagal diupdate');</script>";
        }
    }
    
    function confirms(){
        if($this->model_barang->agrees()){
            echo "<script type='text/javascript'>window.top.window.alertz('alert-success','Sukses !', 'Data berhasil diupdate');</script>";
        }else{
            echo "<script type='text/javascript'>window.top.window.alertz('alert-error','Gagal !', 'Data gagal diupdate');</script>";
        }
    }
    
    function setting(){
        $data['row'] = $this->model_user->fetch_single($this->session->userdata('id'));
        $this->load->view('setting',$data);
    }
    
    function update_set(){
        if($this->model_user->update_set()){
            echo "<script type='text/javascript'>window.top.window.alertu('Setting berhasil diupdate');</script>";
        }else{
            echo "<script type='text/javascript'>window.top.window.alertu('Setting gagal diupdate');</script>";
        }
    }
    
    function cek_nama(){
        $q = $this->input->post('q');
        echo $this->model_user->cek_nama($q);
    }
    
    function cetakjalan() {
        $id = $this->uri->segment(3);
        $data['result'] = $this->model_barang->getBarang($id);

        if (empty($id) or count($data['result']) == 0) {
            redirect('admin/guru/index');
        } else {
            $result = $this->model_barang->getBarang($id);
            $data['id_order'] = $result['id_order'];
            $data['job_order'] = $result['job_order'];
            $data['no_sj'] = $result['no_sj'];
            $data['consgnee'] = $result['consgnee'];
            $data['origin'] = $result['origin'];
            $data['shipper'] = $result['shipper'];
            $data['via'] = $result['via'];
            $data['agent'] = $result['agent'];
            $data['ctn'] = $result['ctn'];
            $data['kg'] = $result['kg'];
            $data['m3'] = $result['m3'];
            $data['invoice'] = $result['invoice'];
            $data['description'] = $result['description'];
            $data['delivery'] = $result['delivery'];
            $data['penerimaan'] = $result['penerimaan'];
            $data['cost'] = $result['cost'];
            $data['profit'] = $result['profit'];
            $data['remarks'] = $result['remarks'];
            $this->load->view('barang/cetakjalan', $data);
        }
    }
    
    function search(){
        $q = $this->input->post('q');
        $field = $this->input->post('field');
        $data['orders'] = $this->model_barang->search($q,$field);
        $this->load->view('agree/showagree', $data);
    }
}
?>
